package com.loop.collection.list;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;

public class CompareDemo {
    public static void main(String[] args) {
        System.out.println(testArrayList());
        System.out.println(testLinkedList());
    }

    /**
     * 测试ArrayList的添加速度
     * @return
     */
    public static long testArrayList(){
        ArrayList<Integer> arrayList = new ArrayList();
        long arrStart = new Date().getTime();
        for (int i = 0; i < 10000; i++) {
            arrayList.add(i);
        }
        long arrStop = new Date().getTime();
        return arrStop-arrStart;
    }

    /**
     * 测试LinkedList的添加速度
     * @return
     */
    public static long testLinkedList(){
        LinkedList<Integer> linkedList = new LinkedList();
        long arrStart = new Date().getTime();
        for (int i = 0; i < 10000; i++) {
            linkedList.add(i);
        }
        long arrStop = new Date().getTime();
        return arrStop-arrStart;
    }
}
